/*
 * Powered By [rapid-framework]
 * Web Site: http://www.rapid-framework.org.cn
 * Google Code: http://code.google.com/p/rapid-framework/
 * Since 2008 - 2013
 */

package com.smg.community.dao;

import java.util.*;

import javacommon.base.*;
import javacommon.util.*;

import cn.org.rapid_framework.util.*;
import cn.org.rapid_framework.web.util.*;
import cn.org.rapid_framework.page.*;
import cn.org.rapid_framework.page.impl.*;

import com.smg.community.model.*;
import com.smg.community.dao.*;
import com.smg.community.service.*;
import com.smg.community.vo.query.*;

/**
 * @author badqiu email:badqiu(a)gmail.com
 * @version 1.0
 * @since 1.0
 */


import org.springframework.stereotype.Repository;


@Repository
public class SmgMemberBehaviorCommentDao extends BaseIbatis3Dao<SmgMemberBehaviorComment,java.lang.Integer>{
	
	@Override
	public String getIbatisMapperNamesapce() {
		return "SmgMemberBehaviorComment";
	}
	
	public void saveOrUpdate(SmgMemberBehaviorComment entity) {
		if(entity.getBcid() == null) 
			save(entity);
		else 
			update(entity);
	}
	
	public Page findPage(SmgMemberBehaviorCommentQuery query) {
		return pageQuery("SmgMemberBehaviorComment.findPage",query);
	}

	public int getCountByType(String behaviorId,String commentType) {
		Map map = new HashMap();
		map.put("behaviorId",behaviorId);
		map.put("commentType",commentType);
		return (Integer) this.getSqlSessionTemplate().selectOne("SmgMemberBehaviorComment.getCountByType", map);
	}

	/**
	 * @param behaviorId
	 * @param commentType 1-评论  -2赞
	 */
	public void updateCountByType(String behaviorId, String commentType) {
			if  ( commentType.equals("1")){
				this.getSqlSessionTemplate().update("SmgMemberBehaviorComment.updateCommentCount", behaviorId);
			}else {
				this.getSqlSessionTemplate().update("SmgMemberBehaviorComment.updatePraiseCount", behaviorId);
			}
	}

	public SmgMemberBehaviorComment getByMemberIdAndBehaviorId(String memberId,
			String behaviorId) {
		Map map = new HashMap();
		map.put("behaviorId",behaviorId);
		map.put("memberId",memberId);
		return (SmgMemberBehaviorComment) this.getSqlSessionTemplate().selectOne("SmgMemberBehaviorComment.getByMemberIdAndBehaviorId", map);
	}
	

}
